//
//  UIAlgorithmViewController.m
//  TestGCD
//
//  Created by StormVCC on 2017/12/7.
//  Copyright © 2017年 StormVCC. All rights reserved.
//

#import "UIAlgorithmViewController.h"

@interface UIAlgorithmViewController ()

@end

@implementation UIAlgorithmViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self calculateMaxNumForK:4];
}


/**
 * 快速排序
 */
- (void)quickPaiXu {
    NSMutableArray *array = [NSMutableArray arrayWithArray:@[@(12),@(3),@(17),@(10),@(100),@(55),@(1),@(23),@(0),@(200),@(33),@(24)]];
    int i = 0 ,j = 0;
    
    
}


/*
 * 冒泡排序
 */
- (void)calculateMaxNumForK:(NSInteger)k {
    NSMutableArray *array = [NSMutableArray arrayWithArray:@[@(2),@(10),@(100),@(55),@(1),@(23),@(0),@(200),@(3),@(4)]];
    NSLog(@"排序前:%@",array);
    NSNumber *temp = @(0);
    for (int i = 0; i < array.count; i++ ) {
        for (int j = array.count - 1; j > i; j --) {
            if ([array[j] intValue] > [array[i] intValue]) {
                temp = array[j];
                array[j] = array[i];
                array[i] = temp;
            }
        }
    }
    NSLog(@"第K个值:%zd",[array[k] intValue]);
    NSLog(@"排序后:%@",array);
}

@end
